﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace InIReaderExample
{
	public partial class FrmMergeFiles : Form
	{
		private List<string> names;

		public FrmMergeFiles(List<string> names)
		{
			InitializeComponent();
			this.names = names;

			comboBox1.AutoCompleteCustomSource.AddRange(names.ToArray());
			comboBox2.AutoCompleteCustomSource.AddRange(names.ToArray());
			comboBox1.Items.AddRange(names.ToArray());
			comboBox2.Items.AddRange(names.ToArray());
		}

		/// <summary>
		///     BNTs the ok click.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">
		///     The <see cref="EventArgs" /> instance containing the event data.
		/// </param>
		private void BntOkClick(object sender, EventArgs e)
		{
			DialogResult = DialogResult.OK;
		}

		/// <summary>
		///     BTNs the cancel click.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">
		///     The <see cref="EventArgs" /> instance containing the event data.
		/// </param>
		private void BtnCancelClick(object sender, EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
		}

		/// <summary>
		/// Checks the input.
		/// </summary>
		private void CheckInput()
		{
			btnOk.Enabled  =	!String.IsNullOrWhiteSpace(comboBox1.Text) &&
								!String.IsNullOrWhiteSpace(comboBox2.Text) &&
								names.Contains(comboBox1.Text) && 
								names.Contains(comboBox2.Text) && 
								!comboBox1.Text.Equals(comboBox2.Text);
		}

		/// <summary>
		/// Comboes the box1 text changed.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
		private void ComboBox1TextChanged(object sender, EventArgs e)
		{
			CheckInput();
		}

		/// <summary>
		/// Comboes the box2 text changed.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
		private void ComboBox2TextChanged(object sender, EventArgs e)
		{
			CheckInput();
		}

		public string File1 { get { return comboBox1.Text; } }
		public string File2 { get { return comboBox2.Text; } }
		public bool Replace { get { return cbReplace.Checked; } }
	}
}
